package com.wpi.smarttour;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.wpi.smarttour.helpers.SmartUploader;
import com.wpi.smarttour.helpers.Utilities;

/* This class is the first Activity that starts
 * when SmartTour is launched from the launcher
 * It uses buttons to start other activities or
 * launch functions 
 */
public class SmartTour extends Activity
{
   // What Activity is running
   public static boolean isMapRunning = false;
   public static boolean isRecordRunning = false;
   // File Uploader
   SmartUploader uploader;

   public void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);
      // Set Layout
      setContentView(R.layout.main);
      Utilities.LogDebug("SmartTour has Started");
      final Button mapButton = (Button) findViewById(R.id.mapButton);
      // SmartUploader
      uploader = new SmartUploader(Utilities.IP_ADDRESS + "/ST/uploader.php");
      // Listener for Button to Map Activity
      mapButton.setOnClickListener(new View.OnClickListener()
      {
         public void onClick(View v)
         {
            // Start Map Activity
            Utilities.LogDebug("Click - Map");
            isMapRunning = true;
            isRecordRunning = false;
            // Start Map Activity
            Intent mapIntent = new Intent(v.getContext(), MapActivity.class);
            startActivity(mapIntent);
         }
      });
      // Button Listener
      final Button recorderButton = (Button) findViewById(R.id.recorderButton);
      recorderButton.setOnClickListener(new View.OnClickListener()
      {
         public void onClick(View v)
         {
            Utilities.LogDebug("Click - Recording");
            isMapRunning = false;
            isRecordRunning = true;
            // Start Recording Activity
            Intent recordIntent = new Intent(v.getContext(), SmartRecording.class);
            startActivity(recordIntent);
         }
      });
      // Button Listener
      final Button uploadButton = (Button) findViewById(R.id.uploadButton);
      uploadButton.setOnClickListener(new View.OnClickListener()
      {
         public void onClick(View v)
         {
            Utilities.LogDebug("Click - Uploading");
            Utilities.msgUserShort("Attempting to Send Video File to Server", getApplicationContext());
            isMapRunning = false;
            isRecordRunning = false;
            // Don't upload if there is no file to upload
            if (SmartRecording.lastRecordedFilePath == "")
            {
               Utilities.msgUser("No files to Upload", getApplicationContext());
            }
            else
            {
               Utilities.msgUserShort("File Uploading Starting", getApplicationContext());
               // Start Uploading
               uploader.setFileName(SmartRecording.lastRecordedFilePath);
               uploader.doStart();
               Utilities.msgUser("File Uploading Finshed", getApplicationContext());
            }
         }
      });
   }
}
